<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            height: 500px;
            width: 500px;
            background-color: plum;
            text-align: center;
            position: relative;
            
        }
        .close{
            width: 20px;
            height: 20px;
            right: 0px;
            background-color: gray;
            text-align: center;
            position: absolute;
            margin-right: 0;
        } 
    </style>
</head>
<body>
    <div class="box">
        <div class="close">x</div>
        广告
    </div>
</body>
<script>
   var box=document.getElementsByClassName('box')[0];
   var close=document.getElementsByClassName('close')[0];
   close.onclick=function(){
    box.style.display='none';
   }
</script>
</html>